package com.uco.oop.innerclass;

import java.util.Arrays;
import java.util.Comparator;

public class AnonymousUse {
    public static void main(String[] args) {


        Student Tom = new Student(19 , "Tom");
        Student Jack = new Student(30 , "Jack");
        Student s2 = new Student(21 , "Lily");

        Student[] s = new Student[]{Tom , Jack , s2};

        Arrays.sort(s, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });
        // lamda表达式简写规则
        // 形参可以不写，如果只有一个参数，括号都不用写
        // 如果方法体只有一行，大括号可以不写，分号也可以不写，return也不用写
        Arrays.sort(s, (o1, o2) -> o1.getAge() - o2.getAge());

        for(Student st : s) {
            System.out.println(st);
        }
    }
}


